import React from 'react';
import Register from '../components/register';
import Reviewer from '../components/reviewer';
import { connect } from 'react-redux';
import Tabs from 'antd/lib/tabs';
import { Link } from 'react-router';
import { getUserInfo, register } from '../actions/sign';
import NormalHeaderBar from '../components/NormalHeaderBar';
import { hashHistory } from 'react-router';
import NoticePage from './noticepage';

const TabPane = Tabs.TabPane;

const styles = {
    form: {
        width: "80%",
        margin: "10% 10% 0% 10%"
    }
};

class ReviewerPage extends React.Component {

    constructor(props) {
        super(props);
        this.handleSubmit = this.handleSubmit.bind(this);
        this.state = {
            role: 2,
            showLegal:false
        }
    }

    handleSubmit(values) {
        let userInfo = {};
        userInfo.OpenId = this.props.params.openid;
        if (this.state.role==1) {
            userInfo.Role = "HCP";
            userInfo.Province = values.address[0];
            userInfo.City = values.address[1];
            userInfo.Hospital = values.hospital;
            userInfo.Department = values.department;
            userInfo.JobTitle = values.jobTitle;
            userInfo.NickName = sessionStorage.nickname;
            userInfo.TrueName = values.name;
            userInfo.TelNumber = values.telNumber;
            userInfo.Email = values.email;
            userInfo.IsInternal = false;
        }
        if (this.state.role==2) {
            userInfo.Role = "HCP";
            userInfo.NickName = sessionStorage.nickname;
            userInfo.TrueName = values.name;
            userInfo.Email = values.email;
            userInfo.IsInternal = true;
        }
        this.props.register(JSON.stringify(userInfo));
    }

    showLegal() {
        this.setState({ showLegal: !this.state.showLegal });
    }

    tabChange(key) {
        this.setState({ role: key });
    }

    render() {
        let defaultCity=['其他', '其他'];
        if (this.props.initProfile != undefined && this.props.initProfile.user != undefined && this.props.initProfile.user.UserInfo != undefined) {
            let province = this.props.initProfile.user.UserInfo.province || '';
            let city = this.props.initProfile.user.UserInfo.city || '';
            defaultCity=[province, city];
        }

        let cities = [];
        if (this.props.initProfile != undefined && this.props.initProfile.cities != undefined ) {
            cities = this.props.initProfile.cities;
        }

        return (
            <div id='register'>
                <NormalHeaderBar title="用户申请"/>
                    <div style={{margin:"1rem"}}>
                         <Reviewer
                            handleSubmit={this.handleSubmit}
                            showLegal={this.showLegal.bind(this) }
                            />
                    </div>
                {   
                    this.state.showLegal && 
                    (<div onClick={this.showLegal.bind(this)} style={{position: "absolute",top: "0px",backgroundColor: "#fff",zIndex: "999"}}>
                        <NoticePage showBack={true}/>
                    </div>)
                }
            </div>    
        );
    }
}

function mapStateToProps(state) {
    return {
        initProfile: state.sign.userInfo,
    }
}

export default connect(mapStateToProps, { getUserInfo, register })(ReviewerPage);